<template>
  <div id="app">
    <h2>测试题</h2>
    <subject
      @sum="fn"
      v-for="(item, index) in list"
      :key="index"
      :item="item"
      :index="index"
    ></subject>
    <div>
      <flag
        :item="item"
        :index="index"
        v-for="(item, index) in list"
        :key="index"
      ></flag>
    </div>
  </div>
</template>

<script>
import subject from "./components/App.vueday 04 作业2组件-1.vue";
import flag from "./components/App.vueday 04 作业2组件-2.vue";
export default {
  components: {
    subject,
    flag,
  },

  data() {
    return {
      list: [
        {
          num1: parseInt(Math.random() * 100),
          num2: parseInt(Math.random() * 100),
          mate: "未完成",
        },
        {
          num1: parseInt(Math.random() * 100),
          num2: parseInt(Math.random() * 100),
          mate: "未完成",
        },

        {
          num1: parseInt(Math.random() * 100),
          num2: parseInt(Math.random() * 100),
          mate: "未完成",
        },

        {
          num1: parseInt(Math.random() * 100),
          num2: parseInt(Math.random() * 100),
          mate: "未完成",
        },

        {
          num1: parseInt(Math.random() * 100),
          num2: parseInt(Math.random() * 100),
          mate: "未完成",
        },
      ],
    };
  },

  methods: {
    fn(index, sumNum) {
      if (sumNum == this.list[index].num1 + this.list[index].num2) {
        this.list[index].mate = "正确";
      } else {
        this.list[index].mate = "错误";
      }
    },
  },
};
</script>

<style>
body {
  background-color: #eee;
}

#app {
  background-color: #fff;
  width: 500px;
  margin: 50px auto;
  box-shadow: 3px 3px 3px rgba(0, 0, 0, 0.5);
  padding: 2em;
}
</style>